package file;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class BufferIo {

	public static void main(String[] args) throws IOException {
		better();
	}

	public static void good() throws IOException {
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
				"demo/good.txt"));
		BufferedOutputStream bos = new BufferedOutputStream(
				new FileOutputStream("demo/better.txt"));
		int b = 0;
		while ((b = bis.read()) != -1) {
			bos.write(b);
			// 这个必须
			bos.flush();
		}
		bos.close();
		bis.close();

	}
	public static void better() throws IOException{
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
				"demo/good.txt"));
		BufferedOutputStream bos = new BufferedOutputStream(
				new FileOutputStream("demo/better.txt"));
		int i = 0;
		byte[] bytes=new byte[1024*8];
		while((i=bis.read(bytes))!=-1){
			bos.write(bytes);
			bos.flush();
		}
		bos.close();
		bis.close();
	}
}
